package com.example.work3.Fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.example.work3.CityWeather_Activity;
import com.example.work3.MainActivity;
import com.example.work3.R;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link BlankFragment2#newInstance} factory method to
 * create an instance of this fragment.
 */
public class BlankFragment2 extends Fragment {

    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "title";

    // TODO: Rename and change types of parameters
    private String mParam1;
    private String mParam2;
    private LinearLayout frag_center_layout;

    private TextView textday_one;
    private TextView textday_two;
    private TextView textday_there;
    private TextView textday_four;
    private TextView textday_five;
    private TextView textday_six;

    private String Day;
    private String wendu;
    private String fengxiang;
    private String fengli;
    private String cun;
    private String beijing;
    private String lingshicity;

    List<Fragment> fragmentList;
    List<String> cityList;


    String url1 = "https://api.apishop.net/common/weather/get15DaysWeatherByArea?apiKey=ijDE2g5a3e35965ca638f1115d95e6d51a0155f658307e9&area=";
    private LinearLayout futureLayout;
    private TextView textdayFive;
    private ImageView imgthere;
    private TextView textdaySix;
    private TextView textdayThere;
    private ImageView imgtwo;
    private TextView textdayFour;
    private Button fg2BtBeijing;
    private Button fg2BtShenzhen;
    private Button fg2BtFujian;
    private Button fg2BtXianggang;
    private Button fg2BtXiamen;
    private TextView fg2BtGuangxi;
    private Button fg2BtHaerbing;
    private Button fg2btLijiang;
    private Button fg2btSanya;
    private Button button;
    private TextView textView;
    private Button button2;

    public BlankFragment2() {
        // Required empty public constructor
    }


    public static BlankFragment2 newInstance(String param1) {
        BlankFragment2 fragment = new BlankFragment2();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);


        fragment.setArguments(args);

        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);

            fragmentList = new ArrayList<>();
        }


    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.fragment_blank2, container, false);

        Bundle bundle = getArguments();
        bundle.getString(getArguments().toString());
        String city = bundle.getString("city");
        String url = url1 + city;
        initView(view);


        return view;

    }

    public void onStart() {

        super.onStart();
    }


    public void setData(String string) {
        textday_five.setText(string);
    }


    private void initView(View view) {
        //用于初始化空间操作
        frag_center_layout = view.findViewById(R.id.futureLayout);
        textday_there = view.findViewById(R.id.textday_there);
        textday_four = view.findViewById(R.id.textday_four);

        futureLayout = (LinearLayout) view.findViewById(R.id.futureLayout);

        fg2BtBeijing = (Button) getActivity().findViewById(R.id.fg2_bt_beijing);
        fg2BtShenzhen = (Button) getActivity().findViewById(R.id.fg2_bt_shenzhen);
        fg2BtHaerbing = (Button) getActivity().findViewById(R.id.fg2_bt_haerbing);
         fg2BtXiamen = (Button) getActivity().findViewById(R.id.fg2_bt_xiamen);
        fg2BtGuangxi = (TextView) getActivity().findViewById(R.id.fg2_bt_Guangxi);
       fg2BtXianggang = (Button) getActivity().findViewById(R.id.fg2_bt_xianggang);
        fg2btLijiang = (Button) getActivity().findViewById(R.id.fg2_bt_lijiang);
        fg2btSanya = (Button) getActivity().findViewById(R.id.fg2_bt_sanya);


       button = (Button) getActivity().findViewById(R.id.fg2_bt_lijiang);

        button2 = (Button) getActivity().findViewById(R.id.fg2_bt_sanya);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initView(getView());
        fg2BtBeijing.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //拿到城市名
                String city=fg2BtBeijing.getText().toString().trim();
                //传值并跳转
                Intent intent=new Intent(getActivity(), CityWeather_Activity.class);
                intent.putExtra("city",city);
                startActivity(intent);
            }
        });

        fg2BtShenzhen.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String city=fg2BtShenzhen.getText().toString().trim();
                //传值并跳转
                Intent intent=new Intent(getActivity(), CityWeather_Activity.class);
                intent.putExtra("city",city);
                startActivity(intent);
            }
        });


        fg2BtGuangxi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String city=fg2BtGuangxi.getText().toString().trim();
                //传值并跳转
                Intent intent=new Intent(getActivity(), CityWeather_Activity.class);
                intent.putExtra("city",city);
                startActivity(intent);
            }
        });

        fg2BtHaerbing.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String city=fg2BtHaerbing.getText().toString().trim();
                //传值并跳转
                Intent intent=new Intent(getActivity(), CityWeather_Activity.class);
                intent.putExtra("city",city);
                startActivity(intent);
            }
        });

        fg2BtXiamen.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String city=fg2BtXiamen.getText().toString().trim();
                //传值并跳转
                Intent intent=new Intent(getActivity(), CityWeather_Activity.class);
                intent.putExtra("city",city);
                startActivity(intent);
            }
        });

        fg2BtXianggang.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String city=fg2BtXianggang.getText().toString().trim();
                //传值并跳转
                Intent intent=new Intent(getActivity(), CityWeather_Activity.class);
                intent.putExtra("city",city);
                startActivity(intent);
            }
        });

        fg2btLijiang.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String city=fg2btLijiang.getText().toString().trim();
                //传值并跳转
                Intent intent=new Intent(getActivity(), CityWeather_Activity.class);
                intent.putExtra("city",city);
                startActivity(intent);
            }
        });

        fg2btSanya.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String city=fg2btSanya.getText().toString().trim();
                //传值并跳转
                Intent intent=new Intent(getActivity(), CityWeather_Activity.class);
                intent.putExtra("city",city);
                startActivity(intent);

            }
        });


    }
}